import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 静态路由表
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/index'),
    redirect: '/home',
    name: 'home',
    meta: { title: '主页' },
    children: [
      {
        path: 'home',
        component: () => import('@/views/Home/home'),
        meta: {
          title: '主页'
        }
      },
      {
        path: 'goods',
        component: () => import('@/views/Goods/goods'),
        meta: {
          title: '商品'
        }
      },
      {
        path: 'goodsDetails',
        component: () => import('@/views/Goods/goodsDetails'),
        meta: {
          title: '商品详情'
        }
      },
      {
        path: 'test',
        component: () => import('@/views/Goods/test'),
        meta: {
          title: 'testPAge'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/login'),
    meta: {
      title: '登录'
    }
  },
  {
    path: '/cart',
    component: () => import('@/views/Cart/cart'),
    name: 'cart',
    meta: {
      title: '购物车'
    }
  },
  {
    path: '/order',
    name: 'order',
    component: () => import('@/views/Order/order'),
    children: [
      {
        path: 'paysuccess', name: 'paysuccess', component: () => import('@/views/Order/paysuccess')
      },
      {
        path: 'payment', name: 'payment', component: () => import('@/views/Order/payment')
      }
    ]
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('@/views/User/user'),
    redirect: '/user/orderList',
    children: [
      {
        path: 'orderList',
        name: '订单列表',
        component: () => import('@/views/User/children/order')
      },
      {
        path: 'information', name: '账户资料', component: () => import('@/views/User/children/information')
      },
      {
        path: 'addressList', name: '收货地址', component: () => import('@/views/User/children/addressList')
      },
      {
        path: 'coupon', name: '我的优惠', component: () => import('@/views/User/children/coupon')
      },
      {
        path: 'shop',
        name: '商店',
        component: () => import('@/views/User/children/shop')
      }
    ]
  },
  {
    path: '/checkout', name: 'checkout', component: () => import('@/views/Checkout/checkout')
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/home' }
]

// 路由表不需要变化了
const router = new Router({
  // mode: 'history',
  routes: constantRoutes
})

export default router
